define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'recommend.rlist/index',
        add_url: 'recommend.rlist/add',
        edit_url: 'recommend.rlist/edit',
        delete_url: 'recommend.rlist/delete',
        export_url: 'recommend.rlist/export',
        modify_url: 'recommend.rlist/modify',
    };

    var Controller = {

        index: function () {
            let table = layui.table;
            let cols = []
            let col = []
            $.ajax({
                type: 'POST',
                url: '/admin/column.clist/showColumnByType?type=3',
                dataType: "JSON",
                sync: false,
                contentType: "application/json",
                success: function (res) {

                    col.push({type: 'checkbox'});

                    $.each(res.data, function (index, obj) {
                        let is_search = false;
                        if($.inArray(obj.column,['recommend_compay','recommend_name','recommend_mobile']) >= 0){
                            is_search = true;
                        }
                        if(obj.column == 'id'){
                            col.push({field: obj.column,title: obj.name,search:is_search,width: 80,});
                        }else if(obj.column == 'cate_id'){
                            col.push({field: obj.column,title: obj.name,search: 'select',selectList: {1: '红', 2: '橙',3:'黄',4:'开发中',5:'公海'},width: 80,});
                        }else if(obj.column == 'create_time'){
                            col.push({field: obj.column,title: obj.name,search: 'range',width: 80,});
                        }else if(obj.column == 'status'){
                            col.push({field: obj.column,title: obj.name,search: 'select', selectList: {0: '禁用', 1: '启用'}, templet: ea.table.switch,width: 85});
                        }
                        else{
                            col.push({field: obj.column,title: obj.name,search:is_search,width: 80,});
                        }

                    });
                    col.push( {width: 200, title: '操作', templet: ea.table.tool});
                    cols.push(col);
                    ea.table.render({
                        init: init,
                        toolbar: ['refresh', 'delete','export'],
                        cols: cols
                    });
                    ea.listen();
                }
            });
            // ea.table.render({
            //     init: init,
            //     cols: [[
                    // {type: 'checkbox'},
                    // {field: 'id', title: 'id'},
                    // {field: 'cate_id', title: '分类', search: 'select', selectList: {1: '红', 2: '橙',3:'黄',4:'开发中',5:'公海'}},
                    // {field: 'recommend_compay', title: '推荐公司'},
                    // {field: 'recommend_name', title: '名称'},
                    // {field: 'recommend_mobile', title: '推荐人手机号'},

                    // {field: 'area_code', title: 'area_code'},
                    // {field: 'remark', title: '备注', templet: ea.table.text},
                    // {field: 'recommend_type', title: '1设计师 2 异业'},
                    // {field: 'recommend_birthday', title: 'recommend_birthday'},
                    // {field: 'recommend_hobby', title: 'recommend_hobby'},
                    // {field: 'recommend_taboo', title: 'recommend_taboo'},
                    // {field: 'province_id', title: '省'},
                    // {field: 'city_id', title: '市'},
                    // {field: 'area_id', title: '区县'},
                    // {field: 'address', title: '小区'},
                    // {field: 'floor', title: '楼牌号/楼层'},
                    // {field: 'account_name', title: '账户名称'},
                    // {field: 'account_number', title: '账户号'},
                    // {field: 'bank_name', title: '银行名称'},
                    // {field: 'open_bank', title: '开户行'},
                    // {field: 'action_admin_id', title: '操作人id'},
                    // {field: 'create_time', title: '创建时间'},
                    // {width: 250, title: '操作', templet: ea.table.tool},
            //     ]],
            // });

        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});